/********************************************************************

Defines some common exceptions.

Write Date: 2011/03/23
Author: Deng Nianchen
>>>> The file contains following classes:
>>>> OutOfRangeException

Modify Date: 2011/06/02
Author: Deng Nianchen
>>>> Add classes:
>>>> AllocateMemoryFailException
>>>> NotOOPObjectException

Modify Date: 2011/07/16
Author: Deng Nianchen
>>>> Add classes:
>>>> TypeConvertFailException

Modify Date: 2015/08/17
Author: Apple
>>>> Add classes: InvalidInvokationException, ClassMetaNotFoundException,
     InvalidArgumentException, CreateObjectOnStackException
>>>> Update code and comment style.
>>>> Complete comment of newly created classes.

*********************************************************************/
#pragma once
#include "OOPException.h"



_NS_OOP_BEGIN



/**
 * Exception for signalling out of range errors.
 *
 * @remarks 2011/3/23, Apple
 */
class OutOfRangeException : public OOPException
{
public:

	virtual QString getReason () const {
		return "The index is out of range";
	}

};



/**
 * Exception for signalling the failure of allocating memory.
 *
 * @remarks 2011/3/23, Apple
 */
class AllocateMemoryFailException : public OOPException
{
public:

	virtual QString getReason () const {
		return "Fail to allocate memory";
	}

};



/**
 * Exception for signalling when an object is not an OOPObject (or its
 * descendant) instance.
 *
 * @remarks 2011/3/23, Apple
 */
class NotOOPObjectException : public OOPException
{
public:

	virtual QString getReason () const {
		return "The object is not an OOPObject (or its descendant) instance";
	}

};



/**
 * Exception for signalling type convert errors.
 *
 * @remarks 2011/6/2, Apple
 */
class TypeConvertFailException : public OOPException
{
public:

    TypeConvertFailException (const char * srcTypeStr,
			const char * destTypeStr) :
	_srcTypeStr (srcTypeStr),
	_destTypeStr (destTypeStr)
	{}

    virtual QString getReason () const {
        return QString ("Cannot convert from %1 to %2").arg (_srcTypeStr)
				.arg (_destTypeStr);
    }

private:

	QString _srcTypeStr;
	QString _destTypeStr;

};



/**
 * Exception for signalling invalid invokation of methods.
 *
 * @remarks 2015/08/17, Apple
 */
class InvalidInvokationException : public OOPException
{
public:

	virtual QString getReason () const {
		return "Invoking the function is invalid";
	}

};



/**
 * Signalling when meta info of a class is not found.
 *
 * @remarks 2015/08/17, Apple
 */
class ClassMetaNotFoundException : public OOPException
{
public:

	ClassMetaNotFoundException (QString& r_className) :
	_className (r_className)
	{}

	virtual QString getReason () const {
		return QString ("Meta of class '%1' is not found").arg (_className);
	}

private:

	QString _className;

};



/**
 * Signalling when passing in some invalid arguments to a method.
 *
 * @remarks 2015/08/17, Apple
 */
class InvalidArgumentException : public OOPException
{
public:

	InvalidArgumentException (QString& r_reason) :
	_reason (r_reason)
	{}

	virtual QString getReason () const {
		return QString ("Invalid argument: %1").arg (_reason);
	}

private:

	QString _reason;

};



/**
 * Signalling when trying to create an Object on stack.
 *
 * @remarks 2015/08/17, Apple
 */
class CreateObjectOnStackException : public OOPException
{
public:

	CreateObjectOnStackException () {}

	virtual QString getReason () const {
		return "Cannot create OOP Object on stack, use new operator instead";
	}

};



_NS_OOP_END